/**
 * Created by Salted fish
 * Description:
 * User: 24539
 * Date：2021-08-01
 * Time: 22:37
 */
public class Test8 {
    public static void main(String[] args) {
        int[] arry ={1,2,3,4,5,6,7};
        int k=5;
        int ret =fund(arry,5);
        System.out.println(ret);
    }
    public static int fund(int[] array,int key) {
        int left = 0;
        int right = array.length-1;
        while (left <= right) {
            int mid = (left+right) / 2;
            if(array[mid] > key) {
                right = mid-1;
            }else if(array[mid] < key) {
                left = mid+1;
            }else {
                return mid;
            }
        }
        return -1;
    }
}
